package com.ruoyi.animal.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.animal.mapper.WasteManagementMapper;
import com.ruoyi.animal.domain.WasteManagement;
import com.ruoyi.animal.service.IWasteManagementService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 废弃物处理Service业务层处理
 * 
 * @author gw
 * @date 2025-01-08
 */
@Service
public class WasteManagementServiceImpl implements IWasteManagementService 
{
    @Autowired
    private WasteManagementMapper wasteManagementMapper;

    /**
     * 查询废弃物处理
     * 
     * @param wasteId 废弃物处理主键
     * @return 废弃物处理
     */
    @Override
    public WasteManagement selectWasteManagementByWasteId(Long wasteId)
    {
        return wasteManagementMapper.selectWasteManagementByWasteId(wasteId);
    }

    /**
     * 查询废弃物处理列表
     * 
     * @param wasteManagement 废弃物处理
     * @return 废弃物处理
     */
    @Override
    public List<WasteManagement> selectWasteManagementList(WasteManagement wasteManagement)
    {
        return wasteManagementMapper.selectWasteManagementList(wasteManagement);
    }

    /**
     * 新增废弃物处理
     * 
     * @param wasteManagement 废弃物处理
     * @return 结果
     */
    @Override
    public int insertWasteManagement(WasteManagement wasteManagement)
    {
        wasteManagement.setCreateTime(DateUtils.getNowDate());
        wasteManagement.setCreateBy(SecurityUtils.getUsername());
        return wasteManagementMapper.insertWasteManagement(wasteManagement);
    }

    /**
     * 修改废弃物处理
     * 
     * @param wasteManagement 废弃物处理
     * @return 结果
     */
    @Override
    public int updateWasteManagement(WasteManagement wasteManagement)
    {
        wasteManagement.setUpdateTime(DateUtils.getNowDate());
        wasteManagement.setUpdateBy(SecurityUtils.getUsername());
        return wasteManagementMapper.updateWasteManagement(wasteManagement);
    }

    /**
     * 批量删除废弃物处理
     * 
     * @param wasteIds 需要删除的废弃物处理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteWasteManagementByWasteIds(Long[] wasteIds)
    {
        int deletedCount = 0;
        for (Long wasteId : wasteIds) {
            WasteManagement wasteManagement = wasteManagementMapper.selectWasteManagementByWasteId(wasteId);
            wasteManagement.setDeleteBy(SecurityUtils.getUsername());
            wasteManagement.setDeleteTime(DateUtils.getNowDate());
            wasteManagement.setDelFlag(1);
            wasteManagementMapper.updateWasteManagement(wasteManagement);
            deletedCount ++;
        }
        return deletedCount;
    }

    /**
     * 删除废弃物处理信息
     * 
     * @param wasteId 废弃物处理主键
     * @return 结果
     */
    @Override
    public int deleteWasteManagementByWasteId(Long wasteId)
    {
        WasteManagement wasteManagement = wasteManagementMapper.selectWasteManagementByWasteId(wasteId);
        wasteManagement.setDeleteBy(SecurityUtils.getUsername());
        wasteManagement.setDeleteTime(DateUtils.getNowDate());
        wasteManagement.setDelFlag(1);
        return wasteManagementMapper.updateWasteManagement(wasteManagement);
    }
}
